]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
extensions-tool: Fix removing from settings list
authorFlorian Müllner <fmuellner@gnome.org>
Mon, 25 Nov 2019 00:49:04 +0000 (01:49 +0100)
committerFlorian Müllner <fmuellner@gnome.org>
Mon, 25 Nov 2019 15:18:08 +0000 (16:18 +0100)
When removing a string from a settings list, we iterate over all
existing entries and copy all strings except the one that's being
removed to a new list, which is then written to GSettings.

However we currently always increment the index, so we end up with
a NULL entry in place of the removed entry, which is then interpreted
as the end of the list. In other words, we also remove all entries
that follow the removed string.

Fix this by looping over the list entries instead of the index, and
only increment the index for entries we copy.

https://gitlab.gnome.org/GNOME/gnome-shell/issues/1946

src/extensions-tool/main.c

index 7cc83de9529c070d5321f6640bc13c1c0e710eaf..e9a457018ed14d5da96091f3bfd6952380c38ffc 100644 (file)
@@ -142,9 +142,10 @@ settings_list_remove (GSettings  *settings,
 
   n_values = g_strv_length (list);
   new_value = g_new0 (char *, n_values);
-  for (i = 0, s = (const char **)list; i < n_values; i++, s++)
+  i = 0;
+  for (s = (const char **)list; *s != NULL; s++)
     if (!g_str_equal (*s, value))
-      new_value[i] = g_strdup (*s);
+      new_value[i++] = g_strdup (*s);
 
   g_settings_set_strv (settings, key, (const char **)new_value);
   g_settings_sync ();